package com.uphone.mvpdemo.http;

import android.text.TextUtils;

import com.google.gson.JsonObject;
import com.radish.baselibrary.utils.LogUtils;
import com.radish.baselibrary.utils.ToastUtil;

import io.reactivex.functions.Consumer;

public class FailureConsumer implements Consumer<Throwable> {

    private String url = "";

    public FailureConsumer() {
    }

    public FailureConsumer(String url) {
        this.url = url;
    }

    @Override
    public void accept(Throwable throwable) throws Exception {
        LogUtils.e("获取网络数据失败:  " + url + "  " + throwable.toString());
        ToastUtil.showShort("联网失败");
        throwable.printStackTrace();
    }

    public static void showMessage(JsonObject jsonObject) {
        String msg = jsonObject.get("msg").getAsString();
        if (!TextUtils.isEmpty(msg)) {
            ToastUtil.showShort(msg);
        }
    }

}
